// pages/work8/index.js
const baseurl='https://free-api.heweather.net/s6/weather?key=726ff01e4d604003abccfbef805de9a2&location='
Page({
    data:{
        city:"",
        temperature:'',
        direct:'',
        latitude:0,
        longitude:0,
    },
    input(e){
        console.log(e)
        this.setData({
            city:e.detail.value
        })
    },
    
        search(){
            let city=this.data.city
            let latitude = this.data.latitude
            let longitude = this.data.longitude
            
            
        },
        onLoad(){
            let that = this
            
            wx.getLocation({
              success(e){
                  let {latitude,longitude}=e
                  let url = `${baseurl}${longitude},${latitude}`
                  wx.request({
                    url,
                    
                   
                    success(e){
                        console.log(e.data.HeWeather6[0])
                        let {windDir,windSpeed} = e
                        that.setData({
                          tmp:e.data.HeWeather6[0].now.tmp,
                          direct:windDir,
                          windSpeed:windSpeed,
                          humidity:e.data.HeWeather6[0].now.hum,
                          pres:e.data.HeWeather6[0].now.pres,
                          text:e.data.HeWeather6[0].now.cond_txt,
                          windScale:e.data.HeWeather6[0].now.wind_sc,
                          wind_dir:e.data.HeWeather6[0].now.wind_dir,
                          city:e.data.HeWeather6[0].basic.parent_city,
                          loc:e.data.HeWeather6[0].basic.location,
                          data:e.data.HeWeather6[0].daily_forecast[0].date,
                          tmpMax:e.data.HeWeather6[0].daily_forecast[0].tmp_max,
                          tmpMin:e.data.HeWeather6[0].daily_forecast[0].tmp_min,
                          ctxt:e.data.HeWeather6[0].daily_forecast[0].cond_txt_d,
                          data1:e.data.HeWeather6[0].daily_forecast[1].date,
                          tmpMax1:e.data.HeWeather6[0].daily_forecast[1].tmp_max,
                          tmpMin1:e.data.HeWeather6[0].daily_forecast[1].tmp_min,
                          ctxt1:e.data.HeWeather6[0].daily_forecast[1].cond_txt_d,
                          data2:e.data.HeWeather6[0].daily_forecast[2].date,
                          tmpMax2:e.data.HeWeather6[0].daily_forecast[2].tmp_max,
                          tmpMin2:e.data.HeWeather6[0].daily_forecast[2].tmp_min,
                          ctxt2:e.data.HeWeather6[0].daily_forecast[2].cond_txt_d,
                          hum:e.data.HeWeather6[0].now.hum
                        })
                    }
                  })
                  that.setData({
                      latitude,longitude
                  })
              }
            })                      
        }      
})

